package com.anolesoft.yr.mbus.code.controller;

import com.anolesoft.common.core.constant.HttpStatus;
import com.anolesoft.common.core.web.domain.AjaxResult;
import com.anolesoft.yr.mbus.code.dto.CodeMaxSequenceQueryDTO;
import com.anolesoft.yr.mbus.code.service.CodeMaxSequenceService;
import com.anolesoft.yr.mbus.code.vo.CodeMaxSequenceQueryVO;
import com.anolesoft.yr.util.Constants;
import com.anolesoft.yr.util.PageData;
import com.anolesoft.yr.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author zhj
 * @date 2020/9/27 19:57
 */
@RestController
@RequestMapping("/api/code/codemaxsequence")
public class CodeMaxSequenceController {
    @Autowired
    private CodeMaxSequenceService codeMaxSequenceService;

    @GetMapping(value = "/list/condition/page", produces = MediaType.APPLICATION_JSON_VALUE)
    public AjaxResult selectList(CodeMaxSequenceQueryVO codeMaxSequenceQueryVO) {
        CodeMaxSequenceQueryDTO codeMaxSequenceQueryDTO = CodeMaxSequenceQueryDTO.builder()
                .codeMainCodeName(codeMaxSequenceQueryVO.getCodeMainCodeName())
                .build();
        Integer limit = codeMaxSequenceQueryVO.getRows();
        Integer curr = codeMaxSequenceQueryVO.getPage();
        PageData<List<CodeMaxSequenceQueryDTO>> pageData = codeMaxSequenceService.selectList(codeMaxSequenceQueryDTO, limit, curr);
        List<CodeMaxSequenceQueryVO> vos = pageData.getItems().stream().map(t->CodeMaxSequenceQueryVO.builder()
                .codeItemUid(t.getCodeItemUid())
                .codeMainCodeDesc(t.getCodeMainCodeDesc())
                .codeMainCodeName(t.getCodeMainCodeName())

                .codeMainGeneClass(t.getCodeMainGeneClass())
                .codeMainUid(t.getCodeMainUid())
                .maxSequence(t.getMaxSequence())
                .objuid(t.getObjuid())
                .propertyValue(t.getPropertyValue())
                .sequenceName(t.getSequenceName())
                .build()).collect(Collectors.toList());
        PageInfo<List<CodeMaxSequenceQueryVO>> pageInfo = new PageInfo<>(limit, pageData.getTotal(), vos);
        return new AjaxResult(HttpStatus.SUCCESS, Constants.QUERY_SUCCESS_MESSAGE, pageInfo);
    }
}
